package cn.elwy.rcp.ui.explorer.composite;

import java.util.List;

import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

import cn.elwy.common.util.ConvertTypeUtil;
import cn.elwy.rcp.ui.explorer.core.vo.FtpInfo;

public class ReleaseComposite extends Composite {
	private Text releaseIpText;
	private Text releaseUserText;
	private Text releasePasswordText;
	private Table table;
	private Text releasePortText;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ReleaseComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new GridLayout(1, false));

		Group group = new Group(this, SWT.NONE);
		group.setLayout(new GridLayout(4, false));
		group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		group.setText("发布设置");

		Label lblNewLabel = new Label(group, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel.setText("IP地址：");

		releaseIpText = new Text(group, SWT.BORDER);
		releaseIpText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Label label = new Label(group, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("端　口：");

		releasePortText = new Text(group, SWT.BORDER);
		releasePortText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Label lblNewLabel_1 = new Label(group, SWT.NONE);
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_1.setText("用户名：");

		releaseUserText = new Text(group, SWT.BORDER);
		releaseUserText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Label lblNewLabel_2 = new Label(group, SWT.NONE);
		lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_2.setText("密　码：");

		releasePasswordText = new Text(group, SWT.BORDER | SWT.PASSWORD);
		releasePasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

		Group group_1 = new Group(this, SWT.NONE);
		group_1.setLayout(new GridLayout(1, false));
		group_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		group_1.setText("部署设置");

		CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(group_1,
				SWT.BORDER | SWT.FULL_SELECTION);
		table = checkboxTableViewer.getTable();
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

		TableViewerColumn tableViewerColumn = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
		TableColumn tblclmnIp = tableViewerColumn.getColumn();
		tblclmnIp.setWidth(100);
		tblclmnIp.setText("IP地址");

		TableViewerColumn tableViewerColumn_3 = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
		TableColumn tableColumn_2 = tableViewerColumn_3.getColumn();
		tableColumn_2.setWidth(100);
		tableColumn_2.setText("端口");

		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
		TableColumn tableColumn_1 = tableViewerColumn_2.getColumn();
		tableColumn_1.setWidth(120);
		tableColumn_1.setText("部署名称");

		TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
		TableColumn tableColumn = tableViewerColumn_1.getColumn();
		tableColumn.setWidth(100);
		tableColumn.setText("用户名");

	}

	@Override
	protected void checkSubclass() {
	}

	public FtpInfo getRelease() {
		FtpInfo ftpInfo = new FtpInfo();
		ftpInfo.setIp(releaseIpText.getText().trim());
		Integer port = ConvertTypeUtil.toInteger(releasePortText.getText().trim(), 21);
		ftpInfo.setPort(port);
		ftpInfo.setUserName(releaseUserText.getText().trim());
		ftpInfo.setPassword(releasePasswordText.getText().trim());
		return ftpInfo;
	}

	public List<FtpInfo> getDeployList() {
		return null;
	}

}
